//
//  UIBarButtonItem+Extension.swift
//  dwdWb
//
//  Created by Dengdwd on 15/10/9.
//  Copyright © 2015年 dwd. All rights reserved.
//

import Foundation
import UIKit

extension UIBarButtonItem {

    class func item(imageName:String = "",title:String = "",target: AnyObject?, action: Selector)->UIBarButtonItem {
        let btn = UIButton()
        if imageName.characters.count > 0 {
        btn.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        btn.setImage(UIImage(named: "\(imageName)_highlighted"), forState: UIControlState.Highlighted)
        }
        if title.characters.count > 0 {
        btn.setTitle(title, forState: UIControlState.Normal)
        btn.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        btn.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Highlighted)
        }
        btn.addTarget(target, action: action, forControlEvents: UIControlEvents.TouchUpInside)
        btn.sizeToFit()
        return UIBarButtonItem(customView: btn)
    
    }


}